package com.free.instadownload.fragment;

import android.annotation.SuppressLint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.free.instadownload.MainActivity;
import com.free.instadownload.R;
import com.free.instadownload.util.Utils;

@SuppressLint("NewApi")
public class DownloadFragment extends Fragment implements OnClickListener{
	public static final String ARG_PAGE = "page";
	private String link="";
	private MainActivity activity;
	private EditText etLink;
	private Button btnPaste;
	private ImageView ivPoster;
	private ImageView ivPosterV;
	private String type="";
	private String media_id="";
	
	
	public static DownloadFragment create(int pageNumber){
		DownloadFragment fragment = new DownloadFragment();
		Bundle args = new Bundle();
        args.putInt(ARG_PAGE, pageNumber);
        fragment.setArguments(args);
        return fragment;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
	    StrictMode.setThreadPolicy(policy);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.page_download, container, false);
		etLink = (EditText) viewGroup.findViewById(R.id.etLink);
		btnPaste = (Button) viewGroup.findViewById(R.id.btnPaste);
		ivPoster = (ImageView) viewGroup.findViewById(R.id.ivPoster);
		ivPosterV = (ImageView) viewGroup.findViewById(R.id.ivPosterV);
		btnPaste.setOnClickListener(this);
		
		
		return viewGroup;
	}
	
	


	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btnPaste:
			doPaste();
			break;

		default:
			break;
		}
	}
	
	public void doPaste(){
		Log.d("CLIP_BOARD", Utils.readFromClipboard(activity));
	}
	
	private class MyAsyncTask extends AsyncTask<Void, Void, Void>{
		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
			super.onPreExecute();
		}
		
		
		
		@Override
		protected Void doInBackground(Void... arg0) {
			// TODO Auto-generated method stub
			return null;
		}
		
		@Override
		protected void onProgressUpdate(Void... values) {
			// TODO Auto-generated method stub
			super.onProgressUpdate(values);
		}
		
		@Override
		protected void onPostExecute(Void result) {
			// TODO Auto-generated method stub
			super.onPostExecute(result);
//			Log.d("LINK_MEDIA", Utils.getLinkMedia(Utils.getMediaID("http://instagram.com/p/BUG/"), Utils.getTypeMedia(Utils.getMediaID("http://instagram.com/p/BUG/"))).get("low_resolution"));
			if(Utils.getMediaID("http://instagram.com/p/BUG") == null){
				Log.d("INVALID", "INVALID LINK");
			}
		}
	}

}
